package com.fh.controller.cuijimanage;

import java.io.*;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.druid.sql.visitor.functions.Char;
import com.fh.annotation.SysLog;
import com.fh.model.loan.*;
import com.fh.util.*;
import com.fh.util.imageUtil.ImageRemarkUtil;
import com.github.pagehelper.PageHelper;
import com.ybd.common.component.redis.StringRedisUtil;
import com.ybd.common.mask.MaskTypeEnum;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fh.controller.base.BaseController;
import com.fh.model.Page;
import com.fh.service.cuijimanage.CuijimanageServiceImpl;
import com.fh.service.cuijimanage.HisOverdueBillInfoService;
import com.fh.service.cuijimanage.TransferHistoryInfoServiceImpl;
import com.fh.service.cuijimanage.UserContactsInfoService;
import com.fh.service.system.user.UserService;
import com.fh.util.mail.DateUtil;

/**
 * Created by Administrator on 2017/5/8/008.
 */
@Controller
@RequestMapping(value = "/cuijimanage")
public class CuijiManageController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(CuijiManageController.class);

    @Autowired
    private CuijimanageServiceImpl cuijimanageServiceImpl;

    @Autowired
    private UserContactsInfoService userContactsInfoService;

    @Resource(name = "userService")
    private UserService userService;

    @Autowired
    private HisOverdueBillInfoService hisOverdueBillInfoService;

    @Autowired
    private TransferHistoryInfoServiceImpl transferHistoryInfoServiceImpl;
    @Autowired
    private StringRedisUtil stringRedisUtil;

    /**
     * 催收中列表
     *
     * @param page
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/anjianList.do")
    public ModelAndView toAnjianList(Page page) throws Exception {
        ModelAndView mv = new ModelAndView();
        PageData pd;
        pd = this.getPageData();
        /**
         * 调用户模块，把当前用户信息放session
         * */
        UserUtils.setDataRole(pd, userService);
        /**
         * 封装查询条件
         * */
        Map<String, Object> map = new HashMap<>();
        //================高级查询===================
        /**
         * 根据案件编号查询
         * */
        String CALLLOANNID = pd.getString("callLoanNid");
        map.put("CALLLOANNID", StringUtils.isEmpty(CALLLOANNID) ? null : CALLLOANNID.trim());
        //订单号查询
        String repaymentId = pd.getString("repaymentId");
        map.put("repaymentId", StringUtils.isEmpty(repaymentId) ? null : repaymentId.trim());
        //借款人姓名
        String realName = pd.getString("realName");
        map.put("realName", StringUtils.isEmpty(realName) ? null : realName.trim());
        //借款编号
        String borrowNid = pd.getString("borrowNid");
        map.put("borrowNid", StringUtils.isEmpty(borrowNid) ? null : borrowNid.trim());
        /*
         * 催收结果查询
         * */
        String callResult = pd.getString("callResult");
        map.put("callResult", !StringUtils.isEmpty(callResult) && !"-1".equals(callResult) ? callResult.trim() : null);
        /**
         * 根据催收员查询
         * */
        String callUser = pd.getString("callUser");
        map.put("callUser", StringUtils.isEmpty(callUser) ? null : callUser.trim());
        /**
         * 根据电话号码查询
         * */
        String telephone = pd.getString("telephone");
        map.put("telephone", StringUtils.isEmpty(telephone) ? null : telephone.trim());
        /**
         * 根据身份证查询
         * */
        String CONTIDCARD = pd.getString("contIdCard");
        map.put("CONTIDCARD", StringUtils.isEmpty(CONTIDCARD) ? null : CONTIDCARD.trim());
        /**
         * 根据逾期阶段查询
         * */
        String overdueDuration = pd.getString("overdueDuration");
        map.put("overdueDuration", !StringUtils.isEmpty(overdueDuration) && !"0".equals(overdueDuration) ? overdueDuration.trim() : null);
        /**
         * 根据产品名称
         * */
        String productSource = pd.getString("productSource");
        map.put("productSource", !StringUtils.isEmpty(productSource) && !"0".equals(productSource) ? productSource.trim() : null);
        /*
         * 根据逾期天数查询
         * */
        String overdueDateMin = pd.getString("overdueDateMin");
        map.put("overdueDateMin", StringUtils.isEmpty(overdueDateMin) ? null : overdueDateMin.trim());
        String overdueDateMax = pd.getString("overdueDateMax");
        map.put("overdueDateMax", StringUtils.isEmpty(overdueDateMax) ? null : overdueDateMax.trim());
        /**
         * 最小逾期金额
         * */
        String overdueFeeMin = pd.getString("overdueFeeMin");
        if (!StringUtils.isEmpty(overdueFeeMin)) {
            map.put("overdueFeeMin", overdueFeeMin.trim());
        } else {
            map.put("overdueFeeMin", null);
        }
        /*
         * 最大逾期金额
         * */
        String overdueFeeMax = pd.getString("overdueFeeMax");
        if (!StringUtils.isEmpty(overdueFeeMax)) {
            map.put("overdueFeeMax", overdueFeeMax.trim());
        } else {
            map.put("overdueFeeMax", null);
        }
        /**
         * 入案时间开始日期
         * */
        String ruanDayMin = pd.getString("ruanDayMin");
        if (!StringUtils.isEmpty(ruanDayMin)) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date ruanDayMin1 = null;
            try {
                ruanDayMin1 = df.parse(ruanDayMin.trim());
            } catch (Exception e) {
                logger.error("时间转换异常==>{}", e.getMessage());
            }
            map.put("ruanDayMin", ruanDayMin1);
        } else {
            map.put("ruanDayMin", null);
        }
        /**
         * 入案时间结束日期
         * */
        String ruanDayMax = pd.getString("ruanDayMax");
        if (!StringUtils.isEmpty(ruanDayMax)) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date ruanDayMax1 = null;
            try {
                ruanDayMax1 = df.parse(ruanDayMax.trim());
            } catch (Exception e) {
                logger.error("时间转换异常==>{}", e.getMessage());
            }
            map.put("ruanDayMax", ruanDayMax1);
        } else {
            map.put("ruanDayMax", null);
        }
        /*
         *催收时间起始
         * */
        String callTimeMin = pd.getString("callTimeMin");
        if (!StringUtils.isEmpty(callTimeMin)) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date callTimeMin1 = null;
            try {
                callTimeMin1 = df.parse(callTimeMin.trim());
            } catch (Exception e) {
                logger.error("时间转换异常==>{}", e.getMessage());
            }
            map.put("callTimeMin", callTimeMin1);
        } else {
            map.put("callTimeMin", null);
        } /*
         *催收时间结束
         * */
        String callTimeMax = pd.getString("callTimeMax");
        if (!StringUtils.isEmpty(callTimeMax)) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date callTimeMax1 = null;
            try {
                callTimeMax1 = df.parse(callTimeMax.trim());
            } catch (Exception e) {
                logger.error("时间转换异常==>{}", e.getMessage());
            }
            map.put("callTimeMax", callTimeMax1);
        } else {
            map.put("callTimeMax", null);
        }
        /*
         *案件状态（催收中）
         * */
        map.put("status", 1);
        String overdueAmountMax = pd.getString("overdueAmountMax");
        if (!StringUtils.isEmpty(overdueAmountMax)) {
            map.put("overdueAmountMax", overdueAmountMax.trim());
        } else {
            map.put("overdueAmountMax", null);
        }
        /*
         *逾期金额最小
         * */
        String overdueAmountMin = pd.getString("overdueAmountMin");
        if (!StringUtils.isEmpty(overdueAmountMin)) {
            map.put("overdueAmountMin", overdueAmountMin.trim());
        } else {
            map.put("overdueAmountMin", null);
        }
        /*
         *还款时间起始
         * */
        String huankuanDayMin = pd.getString("huankuanDayMin");
        if (!StringUtils.isEmpty(huankuanDayMin)) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date huankuanDayMin1 = null;
            try {
                huankuanDayMin1 = df.parse(huankuanDayMin.trim());
            } catch (Exception e) {
                logger.error("时间转换异常==>{}", e.getMessage());
            }
            map.put("huankuanDayMin", huankuanDayMin1);
        } else {
            map.put("huankuanDayMin", null);
        }
        
        /*
         *还款时间截至
         * */
        String huankuanDayMax = pd.getString("huankuanDayMax");
        if (!StringUtils.isEmpty(huankuanDayMax)) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date huankuanDayMax1 = null;
            try {
                huankuanDayMax1 = df.parse(huankuanDayMax.trim());
            } catch (Exception e) {
                logger.error("时间转换异常==>{}", e.getMessage());
            }
            map.put("huankuanDayMax", huankuanDayMax1);
        } else {
            map.put("huankuanDayMax", null);
        }
        /*
         *最后催收时间起始
         * */
        String lastCallTimeMin = pd.getString("lastCallTimeMin");
        if (!StringUtils.isEmpty(lastCallTimeMin)) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date lastCallTimeMin1 = null;
            try {
            	lastCallTimeMin1 = df.parse(lastCallTimeMin.trim());
            } catch (Exception e) {
                logger.error("时间转换异常==>{}", e.getMessage());
            }
            map.put("lastCallTimeMin", lastCallTimeMin1);
        } else {
            map.put("lastCallTimeMin", null);
        }
        /*
         *最后催收时间结束
         * */
        String lastCallTimeMax = pd.getString("lastCallTimeMax");
        if (!StringUtils.isEmpty(lastCallTimeMax)) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date lastCallTimeMax1 = null;
            try {
            	lastCallTimeMax1 = df.parse(lastCallTimeMax.trim());
            } catch (Exception e) {
                logger.error("时间转换异常==>{}", e.getMessage());
            }
            map.put("lastCallTimeMax", lastCallTimeMax1);
        } else {
            map.put("lastCallTimeMax", null);
        }
        /*
         * 排序
         * */
        String sortFind = pd.getString("sortFindByAmount");
        String sortFindday = pd.getString("sortFindByDay");
        String sortFindBylastcalltime = pd.getString("sortFindBylastcalltime");
        if (StringUtils.isEmpty(sortFind) && StringUtils.isEmpty(sortFindday) && StringUtils.isEmpty(sortFindBylastcalltime) ) {
            map.put("sortFind", "a.status,a.create_time DESC,a.id");
        } else if (!StringUtils.isEmpty(sortFind) && StringUtils.isEmpty(sortFindday) && StringUtils.isEmpty(sortFindBylastcalltime)) {
            if (sortFind.equals("0")) {
                map.put("sortFind", "a.overdue_amount,a.create_time DESC,a.id");
                mv.addObject("sortFindByamount", 0);
            }
            if (sortFind.equals("1")) {
                map.put("sortFind", "a.overdue_amount desc,a.create_time DESC,a.id");
                mv.addObject("sortFindByamount", 1);
            }
        } else if (StringUtils.isEmpty(sortFind) && StringUtils.isEmpty(sortFindBylastcalltime) &&!StringUtils.isEmpty(sortFindday)) {
            if (sortFindday.equals("0")) {
                map.put("sortFind", "a.overdue_date,a.create_time DESC,a.id");
                mv.addObject("sortFindByday", 0);
            }
            if (sortFindday.equals("1")) {
                map.put("sortFind", "a.overdue_date desc,a.create_time DESC,a.id");
                mv.addObject("sortFindByday", 1);
            }
        }else if (StringUtils.isEmpty(sortFind) && StringUtils.isEmpty(sortFindday) && !StringUtils.isEmpty(sortFindBylastcalltime) ) {
            if (sortFindBylastcalltime.equals("0")) {
                map.put("sortFind", "a.last_call_time,a.create_time DESC,a.id");
                mv.addObject("sortFindBylasttime", 0);
            }
            if (sortFindBylastcalltime.equals("1")) {
                map.put("sortFind", "a.last_call_time desc,a.create_time DESC,a.id");
                mv.addObject("sortFindBylasttime", 1);
            }
        } else {
            map.put("sortFind", "a.status,a.create_time DESC,a.id");
        }
        //================高级查询===================
        pd.put("map", map);
        page.setPd(pd);

        String key = "listanjianList" + JSON.toJSONString(page);
        String pageKey = "pageanjianList" + JSON.toJSONString(page);
        List<PageData> pageList = null;
        String pageStr = null;
      		/*if (stringRedisUtil.get(key) != null) {
      			pageList = (List<PageData>) stringRedisUtil.get(key);
      			if (stringRedisUtil.get(pageKey) != null) {
      				pageStr = (String) stringRedisUtil.get(pageKey);
      			}
      			logger.info("=========redis exit=========listanjianList=========");
      		} else {*/
        pageList = cuijimanageServiceImpl.anjianlistPage(page);
        this.updataMask(pageList);//掩码
        //stringRedisUtil.put(key, pageList, 2, TimeUnit.MINUTES);
        //stringRedisUtil.put(pageKey, page.getPageStr(), 10, TimeUnit.MINUTES);
        pageStr = page.getPageStr();


        mv.addObject("pageStr", pageStr);
        mv.addObject("anjianlist", pageList);
        mv.setViewName("cuijimanage/anjianList");
        return mv;
    }

    /**
     * 结案列表
     *
     * @param request
     * @param page
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/jieanList.do")
    public ModelAndView toJieanList(HttpServletRequest request, Page page) throws Exception {
        ModelAndView mv = new ModelAndView();
        PageData pd = new PageData();
        pd = this.getPageData();
        UserUtils.setDataRole(pd, userService);
        Map<String, Object> map = new HashMap<>();
        //================高级查询===================
        /*
         *催收编号
         * */
        String CALLLOANNID = pd.getString("callLoanNid");
        if (!StringUtils.isEmpty(CALLLOANNID)) {
            map.put("CALLLOANNID", CALLLOANNID.trim());
        } else {
            map.put("CALLLOANNID", null);
        }
        /*
         * 手机号
         * **/
        String telephone = pd.getString("telephone");
        if (!StringUtils.isEmpty(telephone)) {
            map.put("telephone", telephone.trim());
        } else {
            map.put("telephone", null);
        }
        /**
         *借款人身份证
         * */
        String CONTIDCARD = pd.getString("contIdCard");
        if (!StringUtils.isEmpty(CONTIDCARD)) {
            map.put("CONTIDCARD", CONTIDCARD.trim());
        } else {
            map.put("CONTIDCARD", null);
        }
        /**
         *借款人姓名
         * */
        String realName = pd.getString("realName");
        if (!StringUtils.isEmpty(realName)) {
            map.put("realName", realName.trim());
        } else {
            map.put("realName", null);
        }
        /**
         * 预期阶段
         * */
        String overdueDuration = pd.getString("overdueDuration");
        if (!StringUtils.isEmpty(overdueDuration) && !overdueDuration.equals("0")) {
            map.put("overdueDuration", overdueDuration.trim());
        } else {
            map.put("overdueDuration", null);
        }
        /**
         * 根据产品名称
         * */
        String productSource = pd.getString("productSource");
        map.put("productSource", !StringUtils.isEmpty(productSource) && !"0".equals(productSource) ? productSource.trim() : null);
        /**
         * 逾期天数
         * */
        /*
         * 根据逾期天数查询
         * */
        String overdueDateMin = pd.getString("overdueDateMin");
        map.put("overdueDateMin", StringUtils.isEmpty(overdueDateMin) ? null : overdueDateMin.trim());
        String overdueDateMax = pd.getString("overdueDateMax");
        map.put("overdueDateMax", StringUtils.isEmpty(overdueDateMax) ? null : overdueDateMax.trim());
        /*
         * 结案时间
         * */
        String jieanDayMin = pd.getString("jieanDayMin");
        if (!StringUtils.isEmpty(jieanDayMin)) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date jieanDayMin1 = null;
            try {
                jieanDayMin1 = df.parse(jieanDayMin.trim());
            } catch (Exception e) {
                logger.error("时间转换异常==>{}", e.getMessage());
            }
            map.put("jieanDayMin", jieanDayMin1);
        } else {
            map.put("jieanDayMin", null);
        }
        String jieanDayMax = pd.getString("jieanDayMax");
        if (!StringUtils.isEmpty(jieanDayMax)) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date jieanDayMax1 = null;
            try {
                jieanDayMax1 = df.parse(jieanDayMax.trim());
            } catch (Exception e) {
                logger.error("时间转换异常==>{}", e.getMessage());
            }
            map.put("jieanDayMax", jieanDayMax1);
        } else {
            map.put("jieanDayMax", null);
        }
        /**
         * 案件状态写死，为已结案案件
         * */
        map.put("status", 2);
        /**
         * 排序逻辑要保留
         * */
        String sortFind = pd.getString("sortFindByAmount");
        String sortFindday = pd.getString("sortFindByDay");
        String sortFindBylastcalltime = pd.getString("sortFindBylastcalltime");
        if (StringUtils.isEmpty(sortFind) && StringUtils.isEmpty(sortFindday) && StringUtils.isEmpty(sortFindBylastcalltime)) {
            map.put("sortFind", "a.status,a.create_time DESC,a.id");
        } else if (!StringUtils.isEmpty(sortFind) && StringUtils.isEmpty(sortFindday) && StringUtils.isEmpty(sortFindBylastcalltime)) {
            if (sortFind.equals("0")) {
                map.put("sortFind", "a.actual_recover_amount,a.create_time DESC,a.id");
                mv.addObject("sortFindByamount", 0);
            }
            if (sortFind.equals("1")) {
                map.put("sortFind", "a.actual_recover_amount desc,a.create_time DESC,a.id");
                mv.addObject("sortFindByamount", 1);
            }
        } else if (StringUtils.isEmpty(sortFind) && StringUtils.isEmpty(sortFindBylastcalltime) && !StringUtils.isEmpty(sortFindday)) {
            if (sortFindday.equals("0")) {
                map.put("sortFind", "a.overdue_date,a.create_time DESC,a.id");
                mv.addObject("sortFindByday", 0);
            }
            if (sortFindday.equals("1")) {
                map.put("sortFind", "a.overdue_date desc,a.create_time DESC,a.id");
                mv.addObject("sortFindByday", 1);
            }
        }else if (StringUtils.isEmpty(sortFind) && StringUtils.isEmpty(sortFindday) && !StringUtils.isEmpty(sortFindBylastcalltime) ) {
            if (sortFindBylastcalltime.equals("0")) {
                map.put("sortFind", "a.last_call_time,a.create_time DESC,a.id");
                mv.addObject("sortFindBylasttime", 0);
            }
            if (sortFindBylastcalltime.equals("1")) {
                map.put("sortFind", "a.last_call_time desc,a.create_time DESC,a.id");
                mv.addObject("sortFindBylasttime", 1);
            }
        }else {
            map.put("sortFind", "a.status,a.end_case_date DESC,a.id");
        }
        //================高级查询===================
        pd.put("map", map);
        page.setPd(pd);
        List<PageData> anjianlist = cuijimanageServiceImpl.caseOverlistPage(page);
        //掩码
        this.updataMask(anjianlist);
        //   mv.addObject("countMoney", CountMoneyUtil.getCountMoney(anjianlist));
        page.setPageList(anjianlist);
        mv.addObject("anjianlist", anjianlist);
        mv.addObject("page", page);
        mv.setViewName("cuijimanage/jieanList");
        return mv;
    }

    /**
     * 掩码
     *
     * @param obj
     */
    private void updataMask(List obj) {
        Map<String, MaskTypeEnum> map1 = new HashMap<>();
        map1.put(Const.CONT_ID_CARD, MaskTypeEnum.IDCARD2);
        map1.put(Const.TELE_PHONE, MaskTypeEnum.MOBILE);
        if (Const.SING_STATUS_ZERO != obj.size()) {
            CoverUtil.setListCover(obj, map1);
        }
    }

    /**
     * 联系人列表
     */
    @RequestMapping(value = "/doLinkManList.do")
    public ModelAndView doLimkManList(HttpServletRequest request) throws Exception {
        String callLoanNid = request.getParameter("callLoanNid");
        String userId = request.getParameter("userId");
        String flag = request.getParameter("flag");
        ModelAndView mv = new ModelAndView();
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("callLoanNid", StringUtils.trimAllWhitespace(callLoanNid));
        try {
            //获取该案件的信息
            CallLoanInfo callLoanInfo = cuijimanageServiceImpl.findCallLoanInfoByUserId(map);
            //获取该案件的联系人信息
            List<UserContactsInfo> userContactsInfoList = cuijimanageServiceImpl.findAllContactsInfoListByUserId(map);
            Map<String, MaskTypeEnum> properties = new HashMap<>();
            properties.put("contIdCard", MaskTypeEnum.IDCARD2);
            if (callLoanInfo.getStatus() == 0 || callLoanInfo.getStatus() == 1 || callLoanInfo.getStatus() == 2) {
                properties.put("contMobile1", MaskTypeEnum.MOBILE);
                properties.put("contMobile2", MaskTypeEnum.MOBILE);
                properties.put("contMobile3", MaskTypeEnum.MOBILE);
            }
            if (userContactsInfoList != null) {
                //加密
                CoverUtil.setListCover(userContactsInfoList, properties);
                logger.info("userContactsInfoList.length==》{}", userContactsInfoList.size());
            }
            mv.addObject("userContactsInfoList1", userContactsInfoList);
            mv.addObject("callLoanInfo", callLoanInfo);
        } catch (Exception e) {
            logger.info("获取联系人和案件信息异常==>{}", e.getMessage());
        }
        mv.addObject("flag", flag);
        mv.setViewName("cuijimanage/linkManList");
        return mv;
    }


    /**
     * 案件标记
     */
    @RequestMapping(value = "/remark.do")
    @ResponseBody
    public Map<String, Object> doRemark(@RequestParam("ids") String[] ids, @RequestParam("ids1") String[] ids1) throws Exception {
        int a = 0;
        if (ids.length != 0) {
            Map<String, Object> para = new HashMap<>();
            para.put("ids", ids);
            para.put("status", 1);
            para.put("updateTime", new Date());
            a = cuijimanageServiceImpl.updateCallRemarkStatus(para);
        }
        int a1 = 0;
        if (ids1.length != 0) {
            Map<String, Object> para1 = new HashMap<>();
            para1.put("ids", ids1);
            para1.put("status", 0);
            para1.put("updateTime", new Date());
            a1 = cuijimanageServiceImpl.updateCallRemarkStatus(para1);
        }
        logger.info("案件标记更新了{}条", a + a1);
        Map<String, Object> resp = new HashMap<>();
        resp.put("num", a + a1);
        return resp;
    }

    /**
     * 获取催收记录
     */
    @RequestMapping(value = "/findAllLog.do")
    @ResponseBody
    public List<CallLoanLog> findAllLog(HttpServletRequest request) throws Exception {

        String callLoanNid = request.getParameter("callLoanNid");
        Map<String, Object> mao = new HashMap<>();
        mao.put("callLoanNid", callLoanNid);
        //获取该案件的信息
        CallLoanInfo callLoanInfo = cuijimanageServiceImpl.findCallLoanInfoByUserId(mao);
        if(callLoanInfo==null){
             callLoanInfo = cuijimanageServiceImpl.findCallLoanOverInfoByUserId(mao);
        }
        List<CallLoanLog> logList = cuijimanageServiceImpl.findAllLogList(mao);
        if (callLoanInfo.getStatus() == 0 || callLoanInfo.getStatus() == 1 || callLoanInfo.getStatus() == 2) {
            Map<String, MaskTypeEnum> propertiesCallLoanLog = new HashMap<>();
            propertiesCallLoanLog.put("toMobile", MaskTypeEnum.MOBILE);
            //加密
            CoverUtil.setListCover(logList, propertiesCallLoanLog);
        }
        for (CallLoanLog callLoanLog : logList) {
            try {
                Date date = callLoanLog.getCreateTime();
                String timestr = DateUtil.getFormatDateTime(date, "yyyy-MM-dd HH:mm:ss");
                callLoanLog.setCreateTimeStr(timestr);
                Integer type = callLoanLog.getCallType();
                if(null != type) {
                    if (type == 1) {
                        callLoanLog.setCallTypeStr("电话");
                    } else if (type == 2) {
                        callLoanLog.setCallTypeStr("网络");
                    } else if (type == 3) {
                        callLoanLog.setCallTypeStr("短信");
                    } else if (type == 4) {
                        callLoanLog.setCallTypeStr("线下面催");
                    } else if (type == 5) {
                        callLoanLog.setCallTypeStr("其他");
                    } else {
                        callLoanLog.setCallTypeStr("无此催收方式");
                    }
                }
                String result = callLoanLog.getCallResult();
                if(!StringUtils.isEmpty(result)) {
                    String callResult = Const.CALLRESULTMAPF.get(callLoanLog.getCallResult()) + "";
                    callLoanLog.setCallResult(callResult);
                }
            } catch (Exception e) {
                logger.error("封装催收记录异常==>{}", e.getStackTrace());
            }
        }
        return logList;
    }

    /**
     * 发短信，动作,0 立即发送 1 定时发送
     */
    @SysLog("催计-发短信")
    @RequestMapping(value = "/doMessage.do")
    @ResponseBody
    public Map<String, Object> doMessage(HttpServletRequest request) throws Exception {
        String conType = request.getParameter("contType");//联系人类型
        String contUserName = request.getParameter("contUserName");//联系人姓名
        String tellPhone = request.getParameter("tellPhone");//手机号码
        String callLoanNid = request.getParameter("callLoanNid");//案件编号
        String mode = request.getParameter("mode");
        String message = request.getParameter("message");//短信内容
        String sendmode = request.getParameter("sendmode");//短信发送模式 0 立即发送 1 定时发送
        String sendTime = request.getParameter("sendTime");//定时发送时间
        String callUser = request.getParameter("callUser"); //催收员
        String realName = request.getParameter("realName");
        CallLoanConverseInfo callLoanConverseInfo = new CallLoanConverseInfo();
        int responsetag = 0;
        if (sendmode.equals("0")) {
            Map<String, String> params = new HashMap<>();
            params.put("phone_num", tellPhone);
            params.put("text", message);
            String res = cuijimanageServiceImpl.sendMessage(params);
            logger.info("短信回执==>{}", res);
            if (!StringUtils.isEmpty(res)) {
                JSONObject resmap = JSON.parseObject(res);
                if (resmap.get("code").equals("200")) {
                    callLoanConverseInfo.setCallLoanNid(callLoanNid);
                    callLoanConverseInfo.setCallUser(Integer.valueOf(callUser));
                    callLoanConverseInfo.setCallType(1);
                    callLoanConverseInfo.setToRealNameType(conType);
                    callLoanConverseInfo.setToRealName(contUserName);
                    callLoanConverseInfo.setToMobile(tellPhone);
                    callLoanConverseInfo.setCallInfo(message);
                    callLoanConverseInfo.setStatus(2);
                    String date = "";
                    try {
                        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                        date = formatter.format(new Date());
                    } catch (Exception e) {
                        logger.error("时间类型转换异常==>{}", e.getMessage());
                    }
                    // callLoanConverseInfo.setRemark(date);
                    callLoanConverseInfo.setConverseTime(date);
                    callLoanConverseInfo.setCreateTime(new Date());
                    callLoanConverseInfo.setUpdateTime(new Date());
                    int a = cuijimanageServiceImpl.insertCallLoanConverseInfo(callLoanConverseInfo);
                    long b = callLoanConverseInfo.getId();
                    logger.info("a={}", callLoanConverseInfo.getId() + b);
                    responsetag = 1;
                }
            } else {
                responsetag = 0;
            }

        } else if (sendmode.equals("1")) {
            callLoanConverseInfo.setCallLoanNid(callLoanNid);
            callLoanConverseInfo.setCallUser(Integer.valueOf(callUser));
            callLoanConverseInfo.setCallType(1);
            callLoanConverseInfo.setToRealNameType(conType);
            callLoanConverseInfo.setToRealName(contUserName);
            callLoanConverseInfo.setToMobile(tellPhone);
            callLoanConverseInfo.setCallInfo(message);
            callLoanConverseInfo.setStatus(1);
            // callLoanConverseInfo.setRemark("");
            callLoanConverseInfo.setConverseTime(sendTime);
            callLoanConverseInfo.setCreateTime(new Date());
            callLoanConverseInfo.setUpdateTime(new Date());
            int a = cuijimanageServiceImpl.insertCallLoanConverseInfo(callLoanConverseInfo);
            long b = callLoanConverseInfo.getId();
            responsetag = 1;
            EhcacheUtil ehCache = EhcacheUtil.getInstance();
            Object obj = ehCache.get("message", "dingshi");
            Map<String, String> params = new HashMap<>();
            params.put("phone_num", tellPhone);
            params.put("text", message);
            params.put("sendtime", sendTime);
            params.put("status", "0");
            params.put("id", b + "");
            if (obj != null) {
                String str = (String) obj;
                List<Map<String, String>> messageList = (List<Map<String, String>>) JSONUtils.parse(str);
                messageList.add(params);
                String str1 = JSONUtils.toJSONString(messageList);
                ehCache.remove("message", "dingshi");
                ehCache.put("message", "dingshi", str1);
            } else {
                List<Map<String, String>> messageList = new ArrayList<>();
                messageList.add(params);
                String str = JSONUtils.toJSONString(messageList);
                ehCache.put("message", "dingshi", str);
            }
            logger.info("获取的发送时间==>{}", sendTime);
        }
        Map<String, Object> mao = new HashMap<>();
        mao.put("num", responsetag);
        return mao;
    }

    /**
     * 删除联系人
     */
    @RequestMapping(value = "/delcontactsInfo.do")
    @ResponseBody
    public Map<String, Object> delcontactsInfo(HttpServletRequest request, @RequestParam("id") String id) {
        logger.info("id==>{}", id);
        int a = cuijimanageServiceImpl.deluserContactsInfoById(id);
        Map<String, Object> mao = new HashMap<>();
        mao.put("num", a);
        return mao;
    }

    @RequestMapping(value = "/getCallLoanConverseInfoList.do")
    @ResponseBody
    public List<CallLoanConverseInfo> getCallLoanConverseInfoList(HttpServletRequest request, @RequestParam("callLoanNid") String callLoanNid) {
        logger.info("callLoanId==>{}", callLoanNid);
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("callLoanNid", callLoanNid);
        List<CallLoanConverseInfo> callLoanConverseInfoList = cuijimanageServiceImpl.findAllConverseInfoListByCallLoanId(paramMap);
        Map<String, MaskTypeEnum> propertiesCallLoanConverseInfo = new HashMap<>();
        propertiesCallLoanConverseInfo.put("toMobile", MaskTypeEnum.MOBILE);
        //加密
        CoverUtil.setListCover(callLoanConverseInfoList, propertiesCallLoanConverseInfo);
        for (CallLoanConverseInfo callLoanConverseInfo : callLoanConverseInfoList) {
            int callType = callLoanConverseInfo.getCallType();
            if (callType == 1) {
                callLoanConverseInfo.setCallTypeStr("短信催收");
                callLoanConverseInfo.setRemark("");
            } else if (callType == 2) {
                callLoanConverseInfo.setCallTypeStr("电话催收");
            } else if (callType == 3) {
                callLoanConverseInfo.setCallTypeStr("实地催收");
            } else {
                callLoanConverseInfo.setCallTypeStr("无此催收方式");
            }
            String torealType = callLoanConverseInfo.getToRealNameType();
            if (torealType.equals("1")) {
                callLoanConverseInfo.setToRealNameType("紧急联系人");
            } else if (torealType.equals("2")) {
                callLoanConverseInfo.setToRealNameType("直系亲属");
            } else if (torealType.equals("3")) {
                callLoanConverseInfo.setToRealNameType("其他联系人");
            } else if (torealType.equals("4")) {
                callLoanConverseInfo.setToRealNameType("借款人");
            } else {
                callLoanConverseInfo.setToRealNameType("无此类型");
            }
            Date date = callLoanConverseInfo.getCreateTime();
            String date1 = DateUtil.getFormatDateTime(date, "yyyy-MM-dd HH:mm:ss");
            callLoanConverseInfo.setConverseTime(date1);
        }
        return callLoanConverseInfoList;
    }

    /**
     * 跳转到案件详情页面
     *
     * @param request
     * @return
     */
    @SysLog("委内详情页面")
    @RequestMapping(value = "/toDescPage.do")
    public ModelAndView toDescPage(HttpServletRequest request,
                                   @RequestParam("callLoanNid") String callLoanNid,
                                   @RequestParam("userId") String userId,
                                   @RequestParam(value = "flag",required = false) String flag,
                                   @RequestParam("repaymentId") String repaymentId
    ) {
        ModelAndView mv = new ModelAndView();
        logger.info("callLoanNid==》{}", callLoanNid);
        logger.info("userId==》{}", userId);
        logger.info("repaymentId==》{}", repaymentId);
        try {
            Map<String, Object> map = new HashMap<>();
            map.put("userId", userId);
            map.put("callLoanNid", StringUtils.trimAllWhitespace(callLoanNid));
            //获取该案件的原有联系人信息
            //List<Map<String, Object>> mapList = cuijimanageServiceImpl.getOldContactsUserInfo(userId);
            List<MidUserContactsInfo> midUserContactsInfo = cuijimanageServiceImpl.getOldContactsUserInfo(userId);
            if (midUserContactsInfo != null) {
                int a = cuijimanageServiceImpl.saveOldContactsUserInfo(midUserContactsInfo, map);
            }
           /* //获取该案件的联系人信息
            List<UserContactsInfo> userContactsInfoList = cuijimanageServiceImpl.findAllContactsInfoListByUserId(map);
            Map<String,MaskTypeEnum> properties = new HashMap<>();
            properties.put("contMobile1",MaskTypeEnum.MOBILE);
            properties.put("contMobile2",MaskTypeEnum.MOBILE);
            properties.put("contMobile3",MaskTypeEnum.MOBILE);
            properties.put("contIdCard",MaskTypeEnum.IDCARD2);
            if(userContactsInfoList!=null){
            //加密
	            CoverUtil.setListCover(userContactsInfoList,properties);
	            logger.info("userContactsInfoList.length==》{}", userContactsInfoList.size());
            }*/

            //获取催收人还款详情
            CallLoanBorrowDetail huankuanmap = cuijimanageServiceImpl.getHuankuanDescByUseridAndBorrowId(userId, repaymentId);
            logger.info("接口获取到的huankuanmap==>{}", huankuanmap);


            //获取该案件的信息
            CallLoanInfo callLoanInfo=null;
            if(StringUtils.isEmpty(flag)) {
                 callLoanInfo = cuijimanageServiceImpl.findCallLoanInfoByUserId(map);
                 if(callLoanInfo==null){
                     callLoanInfo = cuijimanageServiceImpl.findCallLoanOverInfoByUserId(map);
                 }
            }else if("jie".equals(flag)){
                 callLoanInfo = cuijimanageServiceImpl.findCallLoanOverInfoByUserId(map);
            }else{
                callLoanInfo = cuijimanageServiceImpl.findCallLoanInfoByUserId(map);
            }
            if (callLoanInfo != null) {
                //加密
                CoverUtil.setBeanCover(callLoanInfo, "contIdCard", MaskTypeEnum.IDCARD2);
                logger.info("获取到的CallLoanInfo==>{}", callLoanInfo);
            }

            //获取借款人详情    接口改ETL  1 借记卡 2 信用卡
            CallLoanUserInfo callLoanUserInfo = null;
            if (Const.PRO_SOURCE_XIAN_JIN_DAI.equals(callLoanInfo.getProductSource())) {
                callLoanUserInfo = cuijimanageServiceImpl.getUserInfoByType(userId, Const.BANK_TYPE_1);//获取现金贷
            } else if (Const.PRO_SOURCE_KA_DAI.equals(callLoanInfo.getProductSource())) {
                callLoanUserInfo = cuijimanageServiceImpl.getUserInfoByType(userId, Const.BANK_TYPE_2);//获取卡贷
            } else if (Const.PRO_SOURCE_R_360.equals(callLoanInfo.getProductSource())) {
                callLoanUserInfo = cuijimanageServiceImpl.getUserInfoByType(userId, Const.BANK_TYPE_1);//获取融360贷
            } else if (Const.PRO_SOURCE_XIAOFEI_DAI.equals(callLoanInfo.getProductSource())) {
                callLoanUserInfo = cuijimanageServiceImpl.getUserInfoByType(userId, Const.BANK_TYPE_1);//获取消费分期
            } else if (Const.PRO_SOURCE_YOUXI_DAI.equals(callLoanInfo.getProductSource())) {
                callLoanUserInfo = cuijimanageServiceImpl.getUserInfoByType(userId, Const.BANK_TYPE_1);//获取游戏贷
            } else if (Const.PRO_SOURCE_JIAOYU_FENQI.equals(callLoanInfo.getProductSource())) {
                callLoanUserInfo = cuijimanageServiceImpl.getUserInfoByType(userId, Const.BANK_TYPE_1);//获取教育分期
            }else if (Const.YXD360_PRODUCT.equals(callLoanInfo.getProductSource())) {
                callLoanUserInfo = cuijimanageServiceImpl.getUserInfoByType(userId, Const.BANK_TYPE_1);//融360游戏贷
            }else {
                callLoanUserInfo = cuijimanageServiceImpl.getUserInfoByType(userId, Const.BANK_TYPE_1);//获取现金贷
            }
            if (callLoanUserInfo != null) {
                //加密
                Map<String, MaskTypeEnum> mao = new HashMap<>();
                mao.put("mobile", MaskTypeEnum.MOBILE);
                mao.put("mobileBank", MaskTypeEnum.MOBILE);
                CoverUtil.setBeanCover(callLoanUserInfo, mao);
            }
            //获取该案件的三个金额信息
            Map<String, Object> amountMap = cuijimanageServiceImpl.getAmountDesc(userId, repaymentId);
            //获取该案件的罚息信息
            Map<String, Object> faxiMap = cuijimanageServiceImpl.reduInfoToanjianDesc(callLoanNid);
            logger.info("罚息到的faxiMap==>{}", faxiMap);

            //获取该催收人借贷详情By yc
            CallLoanBorrowInfo resultMap = cuijimanageServiceImpl.getanjianDescByUseridAndBorrowId(userId, repaymentId);
            logger.info("催收人借贷详情==>{}", JSON.toJSON(resultMap));
            //获取该借款人的身份证图片
            CallLoanUserCardInfo UserIdCardInfoMap = hisOverdueBillInfoService.getUserIdCardInfo2(userId);
            //获取该借款人最近的20条通话记录By yc 第一个表
            List<CallLoanCallInfo> callRecordList = hisOverdueBillInfoService.getLast20CallRecordList(userId);
            //加密
           /* Map<String,MaskTypeEnum> propertiesCallLoanCallInfo = new HashMap<>();
            propertiesCallLoanCallInfo.put("contMobile",MaskTypeEnum.MOBILE);
            CoverUtil.setListCover(callRecordList,propertiesCallLoanCallInfo);*/
            if (callRecordList.size() < 20) {
                int j = callRecordList.size();
                for (int i = j; i < 20; i++) {
                    callRecordList.add(null);
                }
            }
          
            //获取该案件的流转记录
            List<TransferHistoryInfo> transferHistoryInfoList = transferHistoryInfoServiceImpl.findAllTransferHistoryInfoListByCallLoanId(map);
            int length = transferHistoryInfoList.size();
            for (int k = 0; k < length; k++) {
                if (length > 1 && k != length - 1) {
                    transferHistoryInfoList.get(k).setEndTime(transferHistoryInfoList.get(k + 1).getStartTime());
                }
            }
            if (transferHistoryInfoList.size() < 10) {
                int j = transferHistoryInfoList.size();
                for (int i = j; i < 10; i++) {
                    transferHistoryInfoList.add(null);
                }
            }
            mv.addObject("callLoanInfo", callLoanInfo);//案件信息
            mv.addObject("discMap", resultMap);//催收人借贷详情
            //mv.addObject("userMap", userMap);
            mv.addObject("faxiMap", faxiMap);//罚息信息
            mv.addObject("callLoanUserInfo", callLoanUserInfo);//借款人详情
            mv.addObject("amountMap", amountMap);
            mv.addObject("mao", huankuanmap);//还款详情数据
            mv.addObject("callLoanNid", callLoanNid);
            mv.addObject("userId", userId);
            //mv.addObject("borrowNid", borrowNid);
            // mv.addObject("userContactsInfoList", userContactsInfoList);//联系人列表
            mv.addObject("callRecordList", callRecordList);//催收记录列表
            mv.addObject("UserIdCardInfoMap", UserIdCardInfoMap);//身份证信息
            mv.addObject("transferHistoryInfoList", transferHistoryInfoList);//流转历史记录列表
            mv.addObject("callRecordFilePageIp", Const.Call_SERVICE_IP);//EC呼叫IP
            //当前用户
            mv.addObject("currentRoleID", UserUtils.getRealUser().getROLE_ID());
            mv.setViewName("cuijimanage/anjianDesc");
        } catch (Exception e) {
            mv.setViewName("cuijimanage/doError");
            mv.addObject("exception", e.getMessage());
            if (StringUtils.isEmpty(e.getMessage())) {
                mv.addObject("code", true);
                mv.addObject("msg", e);
            }
        }
        return mv;
    }
    
    /**
     * 通讯录  通讯录列表
     */
    @RequestMapping("getCallHisBookList/{userId}")
    @ResponseBody
    public Object getCallHisBookList(@PathVariable("userId")String userId,Page page){
        //获取该借款人通讯录前20条，第三个表
        PageHelper.startPage(page.getCurrentPage(),page.getShowCount());
        List<CallLoanContactsInfo> callHisBookList = hisOverdueBillInfoService.getCallHisBookTop20List2(userId);
        Map<String ,Object> result = R.setJqGridPage(callHisBookList);
        //加密
          /*  Map<String,MaskTypeEnum> propertiesCallLoanContactsInfo = new HashMap<>();
            propertiesCallLoanContactsInfo.put("contactsMobile",MaskTypeEnum.MOBILE);
            CoverUtil.setListCover(callHisBookList,propertiesCallLoanContactsInfo);*/
          return result;
    }

    /**
     * 至添加联系人页面
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/callectionAdd.do")
    public ModelAndView toCallectionAdd(HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
        String userId = request.getParameter("userId");
        mv.addObject("userId", userId);
        //  mv.addObject("linkManShipMap",Const.linkManShip);
        mv.setViewName("cuijimanage/addLinkMan");
        return mv;
    }


    /**
     * 至添加催收纪录界面
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/addCuishouRecorde.do")
    public ModelAndView toAddCuishouRecorde(String callLoanNid, Integer callUser, @RequestParam(required = false) Integer linkManId, @RequestParam(required = false) String mtype,
                                            @RequestParam(required = false,value = "vicename") String viceName, @RequestParam(required = false,value = "vicephone") String vicePhone) throws UnsupportedEncodingException {
        ModelAndView mv = new ModelAndView();
        mv.addObject("callLoanNid", callLoanNid);
        mv.addObject("callUser", callUser);
        mv.addObject("callType", Const.CALLSHIPMAP);
        CallLoanInfo callLoanInfo = cuijimanageServiceImpl.faxijianmianApplyById(callLoanNid);
        if(callLoanInfo==null){
            Map<String,Object> mao = new HashMap<String,Object>();
            mao.put("callLoanNid",callLoanNid);
            callLoanInfo = cuijimanageServiceImpl.findCallLoanOverInfoByUserId(mao);
        }
        Map<String, Object> contactsInfoMap = new HashMap<>();
        //获取借款人详情    接口改ETL
        if (mtype.equals("m4")) {
            CallLoanUserInfo callLoanUserInfo = null;
            String userId = callLoanInfo.getUserId() + "";
            if ("2".equals(callLoanInfo.getProductSource())) {
                callLoanUserInfo = cuijimanageServiceImpl.getUserInfoByType(userId, "1");//获取现金贷
            } else if ("6".equals(callLoanInfo.getProductSource())) {
                callLoanUserInfo = cuijimanageServiceImpl.getUserInfoByType(userId, "2");//获取卡贷
            } else {
                callLoanUserInfo = cuijimanageServiceImpl.getUserInfoByType(userId, "1");//获取现金贷
            }
            if (callLoanUserInfo != null)
                mv.addObject("toMobile", callLoanUserInfo.getMobile());
            if(linkManId==-123){
                mv.addObject("toMobile", callLoanUserInfo.getComTel());
            }
        } else {
            //获取该案件的联系人信息
            Map<String, Object> parameter = new HashMap<>();
            parameter.put("id", linkManId);
            parameter.put("callLoanNid", callLoanNid);
            contactsInfoMap = cuijimanageServiceImpl.findContactsInfoById(parameter);
        }
        if (!StringUtils.isEmpty(mtype)) {
            String toLinkMobile = null;
            if (mtype.equals("m1")) {
                toLinkMobile = contactsInfoMap.get("m1") + "";
            } else if (mtype.equals("m2")) {
                toLinkMobile = contactsInfoMap.get("m2") + "";
            } else if (mtype.equals("m3")) {
                toLinkMobile = contactsInfoMap.get("m3") + "";
            } else if (mtype.equals("tel")) {
                toLinkMobile = contactsInfoMap.get("mc") + "";
            } else {
                toLinkMobile = "";
            }
            mv.addObject("toLinkMobile", toLinkMobile);
            if (mtype.equals("m4")) {
                contactsInfoMap.put("contUserName", callLoanInfo.getRealName());
                contactsInfoMap.put("contShip", "本人");
                contactsInfoMap.put("realName", callLoanInfo.getRealName());
                //下面if代码是为了在通讯录中添加催计消息,掩码后催计图标消失
            } else if (Objects.equals("m100", mtype)) {
                contactsInfoMap = new HashMap<>();
                contactsInfoMap.put("contUserName", viceName);
                contactsInfoMap.put("contShip", "其他");
                contactsInfoMap.put("realName", callLoanInfo.getRealName());
                mv.addObject("toMobile", vicePhone);
            }
        }
        mv.addObject("toRealName", callLoanInfo.getRealName());
        mv.addObject("currentRoleID", UserUtils.getRealUser().getROLE_ID());
        mv.addObject("contactsInfoMap", contactsInfoMap);
        mv.setViewName("cuijimanage/addCuishouRecord");
        return mv;
    }

    /**
     * 至短信发送操作界面
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/toMessage.do")
    public ModelAndView toMessage(HttpServletRequest request,
                                  @RequestParam("tellPhone") String tellPhone,
                                  @RequestParam("tellPhoneShow") String tellPhoneShow,
                                  @RequestParam("callLoanNid") String callLoanNid,
                                  @RequestParam("id") String id) {
        logger.info("tellphone==>{}", tellPhone);
        logger.info("userId==>{}", id);
        Map<String, Object> mao = new HashMap<>();
        mao.put("id", id);
        mao.put("callLoanNid", callLoanNid);
        Map<String, Object> contactsInfoMap = cuijimanageServiceImpl.findContactsInfoById(mao);
        contactsInfoMap.put("tellPhone", tellPhone);
        contactsInfoMap.put("tellPhoneShow", tellPhoneShow);
        ModelAndView mv = new ModelAndView();
        mv.addObject("contactsInfoMap", contactsInfoMap);
        mv.setViewName("cuijimanage/doMessage");
        return mv;
    }

    @RequestMapping(value = "/toMessage1.do")
    public ModelAndView toMessage1(HttpServletRequest request,
                                   @RequestParam("tellPhone") String tellPhone,
                                   @RequestParam("tellPhoneShow") String tellPhoneShow,
                                   @RequestParam("callLoanNid") String callLoanNid,
                                   @RequestParam("realName") String realName,
                                   @RequestParam("callUser") String callUser) {
        logger.info("tellphone==>{}", tellPhone);
        Map<String, Object> contactsInfoMap = new HashMap<>();
        contactsInfoMap.put("tellPhone", tellPhone);
        contactsInfoMap.put("tellPhoneShow", tellPhoneShow);
        contactsInfoMap.put("contType", 4);
        contactsInfoMap.put("contShip", "本人");
        String realName1 = null;
        Map<String, Object> map = new HashMap<>();
        map.put("callLoanNid", StringUtils.trimAllWhitespace(callLoanNid));
        //获取该案件的信息
        CallLoanInfo callLoanInfo = cuijimanageServiceImpl.findCallLoanInfoByUserId(map);
        realName1 = callLoanInfo.getRealName();
        contactsInfoMap.put("contUserName", realName1);
        contactsInfoMap.put("callUser", callUser);
        contactsInfoMap.put("realName", realName1);
        contactsInfoMap.put("callLoanNid", callLoanNid);
        ModelAndView mv = new ModelAndView();
        mv.addObject("contactsInfoMap", contactsInfoMap);
        mv.setViewName("cuijimanage/doMessage");
        return mv;
    }

    /**
     * 已还总额弹框
     *
     * @param request
     * @return
     * @author yc
     */
    @RequestMapping(value = "/toHuankuanDesc.do")
    public ModelAndView toHuankuanDesc(HttpServletRequest request) {
        String userId = request.getParameter("userId");
        String repaymentId = request.getParameter("repaymentId");
        String callLoanNid = request.getParameter("callLoanNid");
        Map<String, Object> mao = new HashMap<>();
        mao.put("userId", userId);
        mao.put("repaymentId", repaymentId);
        List<RepayRecord> repayList = cuijimanageServiceImpl.findRepayRecordList(mao);

      /*  repayList.forEach(e->{
            e.setUpdateTime(new Date(e.getRecoverTime()));
        });*/
        Double sum = repayList.stream().mapToDouble(x->x.getPartAcountyet().setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue()).sum();
      /*  CallLoanInfo callLoanInfo = cuijimanageServiceImpl.findCallLoanInfoByUserId(mao);
        if(callLoanInfo==null) {
            callLoanInfo = cuijimanageServiceImpl.findCallLoanOverInfoByUserId(mao);
        }*/
        BigDecimal userReduOverdueFee = BigDecimal.valueOf(0).setScale(2,BigDecimal.ROUND_HALF_UP);
      if(repayList.size()>0) {
             userReduOverdueFee = repayList.get(0).getUserReduOverdueFee();
      }
        BigDecimal faxituihui = BigDecimal.valueOf(0).setScale(2,BigDecimal.ROUND_HALF_UP);
       try{
           Map<String, Object> faxiMap = cuijimanageServiceImpl.reduInfoToanjianDesc(callLoanNid);
           if(faxiMap!=null) {
               faxituihui = (BigDecimal) faxiMap.get("faxituihuiz");
           }
       }catch (Exception e){
           e.printStackTrace();
       }
        logger.info("还款记录==>{}",repayList.size()+"----"+sum+"-----"+userReduOverdueFee+"------"+faxituihui);
        ModelAndView mv = new ModelAndView();
        mv.addObject("huankuanlist", repayList);
        mv.addObject("sum",sum);
        mv.addObject("userReduOverdueFee", userReduOverdueFee);
        mv.addObject("faxituihui",faxituihui);
        mv.setViewName("cuijimanage/huankuanDesc");
        return mv;
    }

    /**
     * 联系人信息修改
     *
     * @param userContactsInfo
     * @return
     */
    @RequestMapping(value = "/contactInfoUpdatePage")
    public ModelAndView contactInfoUpdate(UserContactsInfo userContactsInfo) {
        ModelAndView mv = this.getModelAndView();
        HashMap<String, Object> map = new HashMap<String, Object>();

        if (!"".equals(userContactsInfo.getId()) || null != userContactsInfo.getId()) {
            Integer userId = userContactsInfo.getUserId();
            Integer id = userContactsInfo.getId();
            map.put("userId", userId);
            map.put("id", id);
            UserContactsInfo userObj = this.userContactsInfoService.findAllContactsInfoListByUserId(map);
            mv.addObject("userObj", userObj);
            mv.addObject("userId", userObj.getUserId());
        }
        //  mv.setViewName("cuijimanage/addManUpdate");
        mv.setViewName("cuijimanage/addLinkMan");
        return mv;
    }

    /**
     * 新增 联系人保存操作
     *
     * @param userContactsInfo
     * @return
     */
    @SysLog("催收详情-保存借款人联系人信息")
    @RequestMapping(value = "contactinfoadd", method = RequestMethod.POST)
    public ModelAndView contactInfoAdd(UserContactsInfo userContactsInfo) {// TODO
        ModelAndView mv = this.getModelAndView();
        if (StringUtils.isEmpty(userContactsInfo.getContSource())) {
            userContactsInfo.setContSource("1");
        }
        // userContactsInfo.setContShip("待定");
        userContactsInfo.setUpdateTime(new Date());
        userContactsInfo.setCreateTime(new Date());
        int a = 0;
        if (userContactsInfo.getId() != null) {
            a = userContactsInfoService.updateByPrimaryKey(userContactsInfo);
        } else {
            a = userContactsInfoService.saveUserContactsInfo(userContactsInfo);
        }
        if (a == 1) {
            mv.addObject("msg", "操作成功！");
            mv.setViewName("cuijimanage/doSuccess");
        } else {
            mv.addObject("msg", "操作失败！");
            mv.setViewName("cuijimanage/doError");
        }
        return mv;
    }

    /**
     * 新增 催收记录保存操作
     *
     * @param callLoanLog
     * @return
     */
    @SysLog("催收详情-新增催收记录")
    @RequestMapping(value = "addCuishouRecord.do", method = RequestMethod.POST)
    public ModelAndView addRecord(CallLoanLog callLoanLog) {
        ModelAndView mv = this.getModelAndView();
        logger.info("callLoanLog==>{}", JSON.toJSON(callLoanLog));
       /* if (callLoanLog.getPromiseRepaymentDay().getYear() == 100) {
            callLoanLog.setPromiseRepaymentDay(null);
        }*/
        //默认催收方式为打电话
        if (Objects.isNull(callLoanLog.getCallType())) {
            callLoanLog.setCallType(1);
        }
        callLoanLog.setCreateTime(new Date());
        callLoanLog.setUpdateTime(new Date());
        int i = cuijimanageServiceImpl.addRecord(callLoanLog);//执行插入催收记录表
        if (i != 1) {
            mv.addObject("code", "500");
            mv.addObject("msg", "插入数据操作失败");
            mv.setViewName("cuijimanage/doError");
            return mv;
        }
        mv.addObject("code", "200");
        mv.addObject("msg", "操作成功！");
        mv.setViewName("cuijimanage/doSuccess");
        return mv;
    }

    @RequestMapping(value = "IoReadImage", method = RequestMethod.GET)
    public String IoReadImage(String userId, String type, HttpServletResponse response) {
        ImageRemarkUtil.markImageByIcon("static/img/112.png", getImage(userId,type), null, 0, response);
        return null;
    }
    
    @RequestMapping(value = "getImage", method = RequestMethod.GET)
    @ResponseBody
    public String getImageUrl(String userId, String type) {
       return getImage(userId,type);
    }
    
    public String getImage(String userId, String type) {
        CallLoanUserCardInfo UserIdCardInfoMap = hisOverdueBillInfoService.getUserIdCardInfo2(userId);
        String url = "static/img/gantan.jpg";
        if (UserIdCardInfoMap != null) {
            //活体
            if ("h".equals(type)) {
                url = UserIdCardInfoMap.getImage();
            } else if ("z".equals(type)) {
                //正面身份证
                url = UserIdCardInfoMap.getShenfenZ();
            } else if ("f".equals(type)) {
                //反面身份证
                url = UserIdCardInfoMap.getShenfenF();
            }
            
        }
        return url;
    }

}
